# Created by: Nicola Vitale <nivit@FreeBSD.org>
# $FreeBSD: head/www/py-cssselect/Makefile 339634 2014-01-13 21:00:02Z rene $

PORTNAME=	cssselect
PORTVERSION=	0.9.1
CATEGORIES=	www python
MASTER_SITES=	CHEESESHOP http://docs.python.org/:sphinx
PKGNAMEPREFIX=	${PYTHON_PKGNAMEPREFIX}
DISTFILES=	${PORTNAME}-${PORTVERSION}.tar.gz
DIST_SUBDIR=	${PORTNAME}
EXTRACT_ONLY=	${PORTNAME}-${PORTVERSION}.tar.gz

MAINTAINER=	nivit@FreeBSD.org
COMMENT=	Cssselect parses CSS3 Selectors and translates them to XPath 1.0

LICENSE=	BSD

USE_PYTHON=	yes
USE_PYDISTUTILS=	yes
PYDISTUTILS_AUTOPLIST=	yes

OPTIONSFILE=	${PORT_DBDIR}/py-${PORTNAME}/options
OPTIONS_DEFINE=	DOCS

.include <bsd.port.options.mk>

DOCSDIR=	${PREFIX}/share/doc/${PKGNAMEPREFIX}${PORTNAME}
SPHINX_BUILD=	sphinx-build

.include <bsd.port.pre.mk>

.if ${PORT_OPTIONS:MDOCS}
DISTFILES+=	 objects.inv:sphinx
BUILD_DEPENDS=	sphinx-build:${PORTSDIR}/textproc/py-sphinx

post-patch:
	@${REINPLACE_CMD} -e 's,%%DISTDIR%%,${DISTDIR}, ; \
		s,%%PORTNAME%%,${PORTNAME},' \
		${WRKSRC}/docs/conf.py

post-install:
	@${MKDIR} ${STAGEDIR}${DOCSDIR}
	${SETENV} PYTHONPATH="${PYTHONPREFIX_SITELIBDIR}" \
	${SPHINX_BUILD} -N -a -b html \
		${WRKSRC}/docs ${WRKSRC}/docs.html
.for i in html js
	@cd ${WRKSRC}/docs.html && \
		${INSTALL_DATA} *.${i} ${STAGEDIR}${DOCSDIR}
.endfor
	@cd ${WRKSRC}/docs.html && \
		${COPYTREE_SHARE} _static/ ${STAGEDIR}${DOCSDIR}
.endif

.include <bsd.port.post.mk>
